package com.edu.user.service.impl;

import com.api.video.VideoClient;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.HfdVideoInfo;


import com.edu.user.mapper.HfdVideoInfoMapper;
import com.edu.user.service.IHfdVideoInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.vo.PageResultVO;

import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 视频表 服务实现类
 * </p>
 *
 * @author jr
 * @since 2021-04-19
 */
@Service
public class HfdVideoInfoServiceImpl extends ServiceImpl<HfdVideoInfoMapper, HfdVideoInfo> implements IHfdVideoInfoService {

    @Autowired
    private VideoClient videoClient;

    @Override
    public PageResultVO<HfdVideoInfo> getVideoList(Integer currentPage, Integer pageSize, String name) {
        //设置分页信息
        IPage<HfdVideoInfo> iPage = new Page(currentPage, pageSize);

        //条件构造器
        QueryWrapper<HfdVideoInfo> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.eq("title", name);
        }

        IPage pageInfo = this.baseMapper.selectPage(iPage, queryWrapper);

        return new PageResultVO<HfdVideoInfo>(0, "视频信息查询", pageInfo.getTotal(), pageInfo.getRecords());
    }

    @Override
    public Result queryVideo() {
        List<HfdVideoInfo> videoInfoList = this.baseMapper.selectList(null);

        return new Result(true, 0, "视频信息查询", videoInfoList);
    }

    /**
     * 上传文件
     *
     * @param hfdVideoInfo
     * @return
     */
    @Override
    public Result uploadVideo(HfdVideoInfo hfdVideoInfo) {
        return videoClient.uploadVideo(hfdVideoInfo);
    }

    @Override
    public Result bindVideo(HfdVideoInfo hfdVideoInfo) {
        int add = this.baseMapper.updateById(hfdVideoInfo);
        if (add > 0) {
            return new Result(true, 0, "绑定成功");
        } else {
            return new Result(false, 1, "绑定失败");
        }
    }
}
